<?php
/* ------------------------------------------------------------------------
 * AION-KOREA Admin Control Panel
 *
 * @version 1.0
 * @author Taro6222 (AION-KOREA Admin CP main Developer)
 * @link http://redmine.aionkorea.org/projects/ak-admin-cp
 * @license http://creativecommons.org/licenses/by-nc-sa/3.0/deed.ko
 * @APM http://www.apachefriends.org/en/xampp.html
 *
------------------------------------------------------------------------ */

class daoPlayer
{
	/**
	 * Stores the instance of this class.
	 *
	 * @var -
	 */
	private static $instance = null;


	/**
	 * 계정의 캐릭터 전체 수
	 * 
	 * @param unknown_type $id
	 */
	public static function getTotalPlayers( $id=0 )
	{
		//game db
		$db = common::dbConnections(2);

		$query = "SELECT count(*) AS pNum FROM players WHERE account_id={$id}";
		$stmt = $db->fetchOne( $query );

		return $stmt['pNum'];
	}


	public static function getPlayerList()
	{
		//login db
		$db = common::dbConnections(1);
		$db->setFetchMode(Zend_Db::FETCH_OBJ);

		//return fix
		$retArray = array();

		try
		{
			//query
			$query = "SELECT
						*
					FROM account_data
					LIMIT {$limit} OFFSET {$offset}
			";
			$stmt = $db->query( $query );
		}
		catch( Exception $e )
		{
			print $e;
			return array();
		}
		$i=0;
		foreach( $stmt as $obj )
		{
			$name = ( $_SESSION['admincp_session_name'] == $obj->name ) ? "<font color='#F87820'>{$obj->name}</font>" : $obj->name;
			$level = ( $obj->access_level > 0 ) ? "GM [ {$obj->access_level} ]" : "-";
			$activated = ( $obj->activated == 1 ) ? "허용" : "차단";

			$retArray[] = array(
				'id' => $obj->id,
            	'name' => $name,
	            'activated' => $activated,
	            'level' => $level,
	            'membership' => $obj->membership,
	            'ip' => $obj->last_ip,
				'toll' => $obj->toll,
				'player' => daoPlayer::getTotalPlayers($obj->id),
            );
            $i++;
		}

		return $retArray;
	}
}
